package br.unicamp.integralization.dto;

import java.util.ArrayList;
import java.util.List;

public class Allocation implements Cloneable {

	private SubjectGroup mandatorySubjects;
	private List<SubjectGroup> electiveGroups;

	public Allocation() {
		mandatorySubjects = new SubjectGroup();
		electiveGroups = new ArrayList<SubjectGroup>();
	}

	public Allocation clone() {
		Allocation allocation = new Allocation();

		allocation.mandatorySubjects = mandatorySubjects.clone();
		allocation.electiveGroups = new ArrayList<SubjectGroup>();

		for (SubjectGroup subjectGroup : electiveGroups) {
			allocation.electiveGroups.add(subjectGroup.clone());
		}

		return allocation;
	}

	public SubjectGroup getMandatorySubjects() {
		return mandatorySubjects;
	}

	public void setMandatorySubjects(SubjectGroup mandatorySubjects) {
		this.mandatorySubjects = mandatorySubjects;
	}

	public List<SubjectGroup> getElectiveGroups() {
		return electiveGroups;
	}

	public void setElectiveGroups(List<SubjectGroup> electiveGroups) {
		this.electiveGroups = electiveGroups;		
	}

/*	public void addSubject(Subject subject, int subjectGroupIndex) {
		if (subjectGroupIndex < 0) {
			mandatorySubjects.addSubject(subject);
		} else {
			electiveGroups.get(subjectGroupIndex).addSubject(subject);
		}
	}*/

	public void removeSubject(Subject subject, int subjectGroupIndex) {
		if (subjectGroupIndex < 0) {
			mandatorySubjects.removeSubject(subject);
		} else {
			electiveGroups.get(subjectGroupIndex).removeSubject(subject);
		}
	}

	@Override
	public String toString(){
		StringBuilder builder = new StringBuilder();
		builder.append("Obrigatórias:\n");
//		builder.append(mandatorySubjects.toString());
		builder.append("Grupo de eletivas: \n");
		
		for (int i = 0; i < electiveGroups.size(); i++) {
			builder.append("Grupo "+ i+ ":\n");
			builder.append(electiveGroups.get(i).toString());
		}
		
		return builder.toString();
	}
	
}
